(function(angular) {
	'use strict';
	angular.module("fs.waf").factory("jobService", jobService);
	jobService.$inject = [ '$q', 'loggerFactory', 'ajaxServiceFactory' ];
	function jobService($q, loggerFactory, ajaxServiceFactory) {
		var log = loggerFactory.getLogger("jobService");
		
		var ajaxService = ajaxServiceFactory.buildAjaxService({
			getServices : {
				url : 'do/cda/dataList/jobService',
				method : 'post'
			},
			getYesno : {
				url : 'do/cda/dataList/yesno',
				method : 'post'
		}
		});
		
		function getServiceOptions() {
			var defer = $q.defer();
			ajaxService.getServices().then(function(response) {
				defer.resolve(response);
			});
			return defer.promise;
		}
		
		function getYesnoOptions() {
			var defer = $q.defer();
			ajaxService.getYesno().then(function(response) {
				defer.resolve(response);
			});
			return defer.promise;
		}
		
		function getTypeOptions() {
			var option = {
					"data" : [ {
						"value" : "",
						"label" : ""
					}, {
						"value" : "Date",
						"label" : "Date"
					}, {
						"value" : "SQL Date",
						"label" : "SQL Date"
					}, {
						"value" : "Timestamp",
						"label" : "Timestamp"
					} , {
						"value" : "Time",
						"label" : "Time"
					} , {
						"value" : "String",
						"label" : "String"
					} , {
						"value" : "Boolean",
						"label" : "Boolean"
					} , {
						"value" : "Double",
						"label" : "Double"
					} , {
						"value" : "Float",
						"label" : "Float"
					} , {
						"value" : "Long",
						"label" : "Long"
					} , {
						"value" : "Integer",
						"label" : "Integer"
					} , {
						"value" : "Short",
						"label" : "Short"
					} , {
						"value" : "Byte",
						"label" : "Byte"
					} ]
			};
			return option;
		}
		
		function getFormatOptions() {
			var option = {
					"data" : [ {
						"value" : "",
						"label" : ""
					}, {
						"value" : "date",
						"label" : "date"
					}, {
						"value" : "timestamp",
						"label" : "timestamp"
					}, {
						"value" : "time",
						"label" : "time"
					}  ]
			};
			return option;
		}
		
		function initDataOptions(ctrl) {
			ctrl.serviceCodeOptions = {};
			ctrl.customFlagOptions ={};
			ctrl.customFlagOptions.hasEmptyOption = true,
			getServiceOptions().then(function(response) {
				angular.extend(ctrl.serviceCodeOptions, response);
			});
			getYesnoOptions().then(function(response) {
				angular.extend(ctrl.customFlagOptions, response);
			});
			ctrl.typeOptions = getTypeOptions();
		
			ctrl.formatOptions = getFormatOptions();
		}

				
		function checkParameter(params) {
			var hash = {};
			for ( var i in params) {
				if (hash[params[i].name])
					return true;
				hash[params[i].name] = true;
			}
			return false;
		}
		
		
		return {
			initDataOptions : initDataOptions,
			checkParameter : checkParameter
		};
	}
})(angular);